"""
@author: wangkang
@contact: wangkang@autobio.com.cn
@file: main.py
@time: 2020/4/2 11:30
@desc: QA问答
"""

from question_classifier import *
from question_parser import *
from question_answer import *


class ChatBotGraph:
    def __init__(self):
        self.classifier = QuestionClassifier()
        self.parser = QuestionPaser()
        self.searcher = AnswerSearcher()

    def chat_main(self, sent):
        answer = '抱歉，这个问题我暂时无法回答'
        res_classify = self.classifier.classify(sent)
        if not res_classify:
            return answer
        res_sql = self.parser.parser_main(res_classify)
        final_answers = self.searcher.search_main(res_sql)
        if not final_answers:
            return answer
        else:
            return '\n'.join(final_answers)


if __name__ == '__main__':

    handler = ChatBotGraph()
    while 1:
        question = input('用户:')
        answer = handler.chat_main(question)
        final_answers = []
        print('小安:', answer)
